#include "l3tol.h"

/**
 * Convert 3-byte disk addresses to arry of longs.
 * 	(from big-endian architecture to local)
 *
 *	lp = array  of longs, the destination
 *	cp = array  of bytes, the source
 *	nd = number of daddrs to convert
 */
void	l3tol( long lp[], byte cp[] , int nd )
{
    static const short number = 1;
    static const bool machineIsBE = ((byte*)&number)[0] == 0;
    
	byte * a = (byte *) lp;
	byte * b = (byte *) cp;

	for (int i = 0 ; i < nd ; i++) {
        if (!machineIsBE)
        {
            /* big-endian => little-endian (intel) */
            a[3] = 0;
            a[2] = b[0];	// least
            a[1] = b[1];
            a[0] = b[2];	// most
            a += 4;
            b += 3;
        }
        else
        {
            /* big-endian => big-endian */
            *a++ = 0;
            *a++ = *b++;	// least
            *a++ = *b++;
            *a++ = *b++;	// most
        }
	}
}
